/*
 * @Descripttion: 
 * @version: 
 * @Author: wangzhilei
 * @Date: 2021-10-05 10:48:14
 * @LastEditors: wangzhilei
 * @LastEditTime: 2021-10-05 11:06:00
 */
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <signal.h>

void sigroutine(int signo){
    switch (signo)
    {
    case SIGALRM:
        printf("Catch a signal -- SIGALRM\n");
        break;
    
    case SIGVTALRM:
        printf("Catch a signal -- SIGVTALRM\n");
        break;
    }
}
int main(){
    struct itimerval value,ovalue,value2;

    printf("process id is %d\n",getpid());
    signal(SIGALRM,sigroutine);
    signal(SIGVTALRM,sigroutine);

   value.it_interval.tv_sec=1;//设置秒，第一次计时到达秒数
   value.it_interval.tv_usec=0;//设置徽秒
   value.it_value.tv_sec=1; //间隔触发秒数
   value.it_value.tv_usec=0;
   setitimer(ITIMER_REAL,&value,&ovalue);//第三个参数返回已存在的定时器值

   value2.it_value.tv_sec=0;
   value2.it_value.tv_usec=500000;
   value2.it_interval.tv_sec=0;
   value2.it_interval.tv_usec=500000;
   setitimer(ITIMER_VIRTUAL,&value2,&ovalue);

   for(;;);
}